﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Core;

namespace WinClient
{
    public partial class FormTableSelector : Form
    {
        public List<SimpleTableInfo> SelectedTables = new List<SimpleTableInfo>();
        private SimpleTableInfoList m_Tables = null;

        private FormTableSelector()
        {
            InitializeComponent();
        }
        
        public FormTableSelector(string providerName, string connectionString)
            : this()
        {
            this.m_Tables = new SimpleTableInfoList(providerName, connectionString);

            for (int i = 0; i < this.m_Tables.Count; i++)
            {
                this.clbTables.Items.Add(string.Format("{2}:{0}.{1}",
                                                       this.m_Tables[i].Table_Schema,
                                                       this.m_Tables[i].Name,
                                                       this.m_Tables[i].Table_Type
                                             )
                    );
            }
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            this.SelectedTables.Clear();
            for (int i = 0; i < this.clbTables.CheckedItems.Count; i++)
            {
                this.SelectedTables.Add(this.m_Tables[this.clbTables.Items.IndexOf(this.clbTables.CheckedItems[i])]);
            }
            this.Close();
        }
    }
}